package com.xyking.yking.controller;

import com.xyking.yking.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @RequestMapping("/home")
    @ResponseBody
    public Map<String,Object> home(){
        System.out.println("hello springboot!!!");
        Map<String,Object> json = new HashMap<>();
        json.put("success",true);
        json.put("msg","aaa");
        return json;
    }

    @RequestMapping("/toIndex")
    public ModelAndView toIndex(){
        System.out.println("toIndex");
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        //添加数据
        mv.addObject("username",null);
        mv.addObject("sex","人妖");
        List<Student> lst = new ArrayList<>();
        lst.add(new Student(1,"张三"));
        lst.add(new Student(2,"李四"));
        lst.add(new Student(3,"王五"));
        mv.addObject("lst",lst);
        return mv;
    }

}
